<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改电子名片产品配置')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-prd-edit" th:object="${ecardPrdInfo}">
        <input name="prdId" th:field="*{prdId}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">产品名称：</label>
            <div class="col-sm-8">
                <input name="prdName" th:field="*{prdName}" class="form-control" type="text" readonly>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">自定义跳转：</label>
            <div class="col-sm-8">
                <select name="definedSkip" class="selectpicker form-control m-b"
                        th:with="type=${@dict.getType('sys_sts')}" required>
                    <option value="">请选择</option>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                            th:value="${dict.dictValue}" th:field="*{definedSkip}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">公共跳转类型：</label>
            <div class="col-sm-8">
                <select name="skipType" id="skipType" class="selectpicker form-control m-b"
                        th:with="type=${@dict.getType('ecard_prd_skip_type')}" required>
                    <option value="">请选择</option>
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                            th:value="${dict.dictValue}" th:field="*{skipType}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">网页链接：</label>
            <div class="col-sm-8">
                <input name="skipUrl" id="skipUrl" th:field="*{skipUrl}" class="form-control"
                       type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">图片路径：</label>
            <div class="col-sm-8">
                <input type="hidden" name="imgPath" th:field="*{imgPath}">
                <div class="file-loading">
                    <input class="form-control file-upload" id="imgPath" name="file" type="file">
                </div>
            </div>
        </div>

    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
    var prefix = ctx + "ecard/config/prd";
    $("#form-prd-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            if ($("#skipType").val() == 1 && $("#skipUrl").val() == "") {
                $.modal.alert("请填写跳转链接！");
                return;
            }
            if ($("#skipType").val() == 2 && $("#imgPath").val() == "") {
                $.modal.alert("请上传图片！");
                return;
            }
            $.operate.save(prefix + "/edit", $('#form-prd-edit').serialize());
        }
    }

    $(".file-upload").each(function (i) {
        var val = $("input[name='" + this.id + "']").val()
        $(this).fileinput({
            'uploadUrl': ctx + 'common/upload/ecard',
            initialPreviewAsData: true,
            initialPreview: [val],
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })
        $(this).fileinput('_initFileActions');
    });

</script>
</body>
</html>